<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <textarea name="" id="content" cols="30" rows="10"></textarea>
    <div>还可以输入<span id="count">20</span>字符</div>
    <input type="button" value="" id="button">
    <script>
        var count=document.getElementById("count")
        var content=document.getElementById("content")
        var button=document.getElementById("button")
        content.oninput=function(){
            var str=content.value
            if(str.length<=20){
                content.value=str
                var num=20-str.length
                count.innerHTML=num;
            }
            else{
                newstr=str.substr(0,20)
                content.value=newstr
                count.innerHTML=0;
            }
        }
        content.onkeydown=function(e){
            if(e.keyCode==13&&e.ctrlKey==true){
                //e中只有ctrlKey,shiftKey,metaKey,enterKer，所以一般都是这几个键和其他建的组合
               button.onclick() 
            }
        }
        button.onclick=function(){
            var p=document.createElement("p")
               p.innerText=content.value
               console.log(p)
               document.body.appendChild(p) 
        }
    </script>
</body>
</html>